var consultCtrl  = new XFApp.client();
XFApp.client.prototype.consult = {
	successCode : "10000",
	urlItems : {
		submitURL : basePath+"/govConsulation/submit"
	},
	
	submit:function(){
		var replyContent = $("#description").val();
		var valid = false;
/*		if(!replyContent){
			$("#description_tip").show();
			valid = true;
		}else if(replyContent.length>500 || replyContent.length<10){
			$("#description_length_tip").show();
			valid = true;
		}*/
		var title = $("#title").val();
		if(!title){
			$("#title_tip").show();
			valid = true;
		}
		if(valid){
			return;
		}
		var email = $("#quizzerEmail").val();
		if(!!email){
			var szReg=new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$");
			var bChk=szReg.test(email); 
			if(!bChk){
				$("#quizzerEmail_tip").show();
				return;
			}
		}
		var type = 1;
		if($("#zx_checkbox").prop("checked")){
			type=0;
		}
		var _this = this;
		var params = [];
		var param = {name:'type',value:type};
		params.push(param);
		$("input").each(function(){
			if(!!$(this).val() && !!$(this).attr("id")){
				var param = {name:'',value:''};
				param.name=$(this).attr("id");
				param.value=$(this).val();
				params.push(param);
			}
		});
		$("select").each(function(){
			if(!!$(this).val() && !!$(this).attr("id")){
				var param = {name:'',value:''};
				param.name=$(this).attr("id");
				param.value=$(this).val();
				params.push(param);
			}
		});
		$("textarea").each(function(){
			if(!!$(this).val() && !!$(this).attr("id")){
				var param = {name:'',value:''};
				param.name=$(this).attr("id");
				param.value=$(this).val();
				params.push(param);
			}
		});
		
		webDialogUtil.simpleConfrimAlert("是否确认提交", function(){
			$.ajaxFileUpload({
				url : _this.urlItems.submitURL,
				secureuri:false,
				fileElementId:'image',//file标签的id
				dataType: 'json',
				data : params,
				success: function (data, status) {
					if(data.code==20000){
						webAlert({
		                    content:document.getElementById("js_login_box"),
		                    style:'redSkin',
		                    title:false,
		                });
		                $('.k-head').parents('.dialogSkin_redSkin').css({"border-radius":"5px","overflow":"hidden"});
					}else if(data.code!=10000){
						webDialogUtil.simpleAlert(data.msg, "温馨提示");
					}else{
						webDialogUtil.simpleAlert("咨询已提交", "温馨提示");
						$("#zx_dd").hide();
					}
				},
				error: function (data, status, e) {
					webDialogUtil.simpleAlert("处理异常", "温馨提示");
				}
			});
		});
	},
	showIndustryClassify : function(value){
		var content = '<option value="">全部</option>';
		if(!!value && value!=0){
			$("#department").find("option[name='industry"+value+"']").each(function(){
				var box = $('<div></div>');
				var sel = $(this).clone();
				sel.css("display","");
				box.append(sel);
				content+=box.html();
			});
			$("#industryClassify").html(content);
		}else{
			$("#industryClassify").html(content);
			$("#industryClassify").val("");
		}
	},
	event : function(){
		var _this = this;
		$("#submit_btn").on("click",function(){
			_this.submit();
		});
		
		$("#description").on("focus",function(){
			$("#description_tip").hide();
			$("#description_length_tip").hide();
		});
		$("#title").on("focus",function(){
			$("#title_tip").hide();
		});
		$("#quizzerEmail").on("focus",function(){
			$("#quizzerEmail_tip").hide();
		});
		$("#department").on("change",function(){
			_this.showIndustryClassify($(this).val(),null);
		});
	},
};
$(function(){
	consultCtrl.consult.event();
	consultCtrl.consult.showIndustryClassify();
});